//
//  GoodsCommentCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/25.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "GoodsCommentCell.h"

#import "WTKStarView.h"

@interface GoodsCommentCell()

@property (nonatomic,strong) UIImageView *avatarImgV;

@property (nonatomic,strong) UILabel *nameLB;

@property (nonatomic,strong) UILabel *timeLB;

@property (nonatomic,strong) WTKStarView *starView;

@property (nonatomic,strong) UILabel *commentLB;

@property (nonatomic,strong) UIView *lineV;


@end


@implementation GoodsCommentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}
#pragma mark - setter
- (void)setModel:(GoodsCommentModel *)model{
    _model = model;
    
    [self.avatarImgV sd_setImageWithURL:[NSURL URLWithString:_model.photo] placeholderImage:LoadImage(@"个人中心_logo")];
    
    [self.nameLB setText:_model.name];
    self.nameLB.width = [Configuration getLabelWidthWithText:self.nameLB.text withFont:self.nameLB.font];
    self.timeLB.text = _model.time;
    self.timeLB.width = [Configuration getLabelWidthWithText:self.timeLB.text withFont:self.timeLB.font];
    
    self.starView.left = self.nameLB.right+5;
    self.starView.star = _model.star;
    
    self.commentLB.text = _model.comment;
    if (_model.showDetail == YES) {
        self.commentLB.height = [Configuration getLabelHeightWithText:self.commentLB.text withFont:self.commentLB.font withLBWidth:ScreenWidth-30];
        self.commentLB.numberOfLines = 0;
    }
}
#pragma mark - UI
-(void)initUI{
    [self.contentView addSubview:self.lineV];
    [self.contentView addSubview:self.avatarImgV];
    [self.contentView addSubview:self.nameLB];
    [self.contentView addSubview:self.starView];
    [self.contentView addSubview:self.timeLB];
    [self.contentView addSubview:self.commentLB];
}

#pragma mark - lazy

- (UIImageView *)avatarImgV{
    if (!_avatarImgV) {
        _avatarImgV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 32, 32)];
        _avatarImgV.clipsToBounds = YES;
        _avatarImgV.layer.cornerRadius = 16;
    }
    return _avatarImgV;
}

- (UILabel *)nameLB{
    if (!_nameLB) {
        _nameLB = [[UILabel alloc] initWithFrame:CGRectMake(self.avatarImgV.right+6, self.avatarImgV.top-2, 40, 18)];
        _nameLB.textColor = MainGrayTextColor;
        _nameLB.textAlignment = NSTextAlignmentLeft;
        _nameLB.font = FontSet(13);
    }
    return _nameLB;
}

- (UILabel *)timeLB{
    if (!_timeLB) {
        _timeLB = [[UILabel alloc] initWithFrame:CGRectMake(self.avatarImgV.right+6, self.nameLB.bottom, 40, 17)];
        _timeLB.textColor = MainGrayTextColor;
        _timeLB.textAlignment = NSTextAlignmentLeft;
        _timeLB.font = FontSet(12);
    }
    return _timeLB;
}

///星级评分
-(WTKStarView *)starView{
    if (!_starView) {
        _starView = [[WTKStarView alloc] initWithFrame:CGRectMake(self.nameLB.right+5, self.nameLB.top+2, 60, 15) starSize:CGSizeZero withStyle:WTKStarTypeFloat];
        _starView.isTouch = NO;
    }
    return _starView;
}


- (UILabel *)commentLB{
    if (!_commentLB) {
        _commentLB = [[UILabel alloc] initWithFrame:CGRectMake(15, self.timeLB.bottom+8, ScreenWidth-30, 17)];
        _commentLB.textColor = MainBlackTextColor;
        _commentLB.textAlignment = NSTextAlignmentLeft;
        _commentLB.font = FontSet(13);
    }
    return _commentLB;
}

- (UIView *)lineV{
    if (!_lineV) {
        _lineV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 1)];
        _lineV.backgroundColor = MainBackColor;
    }
    return _lineV;
}



@end
